package com.yanqu.road.server.cmd.activity.sonhai;

import com.yanqu.road.entity.activity.sonhai.data.SonHaiBattleLog;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SonHaiProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiActivity;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiActivityMgr;
import com.yanqu.road.server.manager.activity.sonhai.pb.SonHaiActivityPb;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.List;

@Cmd(code = Protocol.C2_SON_HAI_GET_BATTLE_LOG_LIST, desc = "山海伏兽-获取战斗日志LIST")
public class CrossSonHaiGetBattleLogListCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        SonHaiProto.SonHaiGetBattleLogListReqMsg reqMsg = SonHaiProto.SonHaiGetBattleLogListReqMsg.parseFrom(packet.getBytes());
        SonHaiProto.SonHaiGetBattleLogListRespMsg.Builder respMsg = SonHaiProto.SonHaiGetBattleLogListRespMsg.newBuilder();
        CrossSonHaiActivity activity = CrossSonHaiActivityMgr.getActivity(reqMsg.getActivityId(), groupId);
        if (activity == null) {
            respMsg.setRet(GameErrorCode.E_SON_HAI_ACTIVITY_NOT_FOUND);
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_SON_HAI_GET_BATTLE_LOG_LIST, respMsg));
            return;
        }
        //获取战斗日志LIST
        List<SonHaiBattleLog> list = activity.getBattleLogList(reqMsg.getPageNum(), reqMsg.getPageSize(), reqMsg.getUserId());
        //构建pb，返回
        respMsg.setRet(0);
        for (SonHaiBattleLog log : list) {
            SonHaiProto.SonHaiBattleLog.Builder logBuilder = SonHaiActivityPb.buildSonHaiBattleLog(log, reqMsg.getLanguage());
            respMsg.addBattleLog(logBuilder);
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_SON_HAI_GET_BATTLE_LOG_LIST, respMsg));
    }

    @Override
    public void sendData() {

    }
}
